/**  
 * @Title: Game.java
 * @Package com.nubb.model
 * @author maoyun(maoyun0903@163.com)
 * @date 2014-3-27 下午01:35:21
 * @version V1.0
 */ 
package com.limit.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

/** 
 * 具体某个游戏<br/>
 * @author maoyun(maoyun@nubb.com)
 * @date 2014-3-27 下午01:35:21 
 * @version V1.0
 */

public class Game extends Model<Game> {
	
	public final static Game dao = new Game();
	
	/**
	 * cp的游戏
	 */
	public List<Game> getListByAdminId(long admin_id){
		return Game.dao.find("select * from game where admin_id=? order by sort_id desc , online_time desc", admin_id);
	}
	
	/**
	 * 以时间段为节点统计记录数目
	 */
	public int getListByCreateTime(long game_id , int app_type , String start , String end){
		List<Game> games = Game.dao.find("select * from view_downincome_count where game_id=? and app_type=? and create_time between ? and ?" , game_id , app_type , start , end);
		return games.size();
		
	}

	/** 
	 * 排行榜下关联的游戏列表
	 */
	public Page<Game> getGamesByRankId(long rank_id , int pageNow , int pageSize) {
		
		return Game.dao.paginate(
						pageNow, 
						pageSize,
						"select * " , 
						"from view_rank_games where rank_id = ? order by sort_id desc , rank_id ASC" ,
						rank_id);
	}
	
	
	
}
